<%-- 
    Document   : cart
    Created on : Mar 14, 2014, 8:22:12 PM
    Author     : ahmed
--%>

<%@page import="pojo.Mobile"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="header.jsp" %>
<table border="1">
    <tr>
        <td>Name</td>
        <td>Price</td>
        <td>Action</td>
    </tr>
<%
    List mobiles = (List) request.getAttribute("cart");
    for (Object object : mobiles) {
%>
<tr class="cart-item">
    <td class="item-name">
        <%= ((Mobile) object).getName()%>
    </td>
    <td class="item-price">
        <%= ((Mobile) object).getPrice()%>
    </td>
    <td class="item-<%= ((Mobile) object).getId() %>">
        <form>
            <input type="button" value="Checkout" onclick="checkout(<%= ((Mobile) object).getId() %>)"/>
            <input type="button" value="Delete from Cart" onclick="removeItem(<%= ((Mobile) object).getId() %>)" />
        </form>
    </td>
</tr>
<%  }
%>
</table>
<script type="text/javascript">
    function checkout(mobileId) {
        $.post("CheckOut",{mobileId: mobileId},function() {
            window.history.go(0);
        });
    }
    function removeItem(mobileId) {
        $.post("DeleteFromCart",{mobileId: mobileId},function() {
            window.history.go(0);
    });
    }
</script>
<%@include file="footer.jsp" %>
